package threadingexercise;


import java.util.Timer;
import java.util.TimerTask;

//定时器
public class ThreadDemo22Timer {
    public static void main(String[] args) {
        Timer timer = new Timer();
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                System.out.println("hello3");
            }
        },3000);

        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                System.out.println("hello2");
            }
        },2000);

        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                System.out.println("hello1");
            }
        },1000);

        // 程序执行完不会立即结束，
        // 原因：Timer内置了线程，还是前台线程 会阻止进程结束

    }

}
